const express = require('express')
const app = express()
const port = 3000

// 设置跨域
app.use(function(req, res, next) {
  res.header('Access-Control-Allow-Origin', '*')
  res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
  res.header("Access-Control-Allow-Headers", "Content-Type,Content-Length, Authorization, Accept,X-Requested-With");
  next()
})

// 引用路由文件
let barChart = require('./router/bar')
let twoChart = require('./router/two')
let fourChart = require('./router/four')
let pieChart = require('./router/pie')
let mapChart = require('./router/map')

app.get('/', (req, res) => {
  res.send('Hello World!')
})

// 使用中间件来配置路由
app.use('/bar', barChart)
app.use('/two', twoChart)
app.use('/four', fourChart)
app.use('/pie', pieChart)
app.use('/map', mapChart)

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`)
})
